home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
gport.exe
/
GAMDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-30
|
19KB
|
737 lines
/*
// GAMDEMO.C
//
// Game port demo program for the Gport game port library.
//
// Compiled and linked with Borland C++ v2.00
//
// Copyright (c) 1991 Bri Productions
//
*/
#include "gport.h"
#include <stdlib.h>
#include <bios.h>
#include <graphics.h>
#include <alloc.h>
#include <stdio.h>
#include <stdarg.h>
#include <dos.h>
#define AXIS 0 /* GamAxis()/GamStick switch */
#define limit(n,max,min) (n) > (max) ? (max) : ((n) < (min) ? (min) :(n))
/*
//-------------------------------------
//
// screen coordinates, sizes, etc.
//
//-------------------------------------
*/
#define BASE_X 640 /* base with of the screen */
#define BASE_Y 480 /* base with of the screen */
#define XREF 9 /* X scaling reference */
#define YREF 35 /* X scaling reference */
#define OAX 170 /* x origin of joystick a */
#define OAY 175 /* y origin of joystick a */
#define OBX 470 /* x origin of joystick b */
#define OBY 175 /* y origin of joystick b */
#define JR 135 /* joystick radius */
#define TSIZE 5 /* size of tic marks */
#define TSPACE 10 /* spacing of tic marks */
#define TNUM 13 /* number of tic marks */
#define HSIZE 5 /* cross hair size */
#define BAY 350 /* y center of a buttons */
#define BBY 350 /* y center of b buttons */
#define BSPACE 100 /* x space between buttons */
#define BR 20 /* button radius */
#define BON 1 /* button on */
#define BOFF 0 /* button off */
#define GAIN 7 /* gain divisor for Gport */
#define BIOS_GAIN 14 /* gain multiplier for bios*/
#define Y_COORD_OFF 235 /* Y coordinate offset */
#define JAY_COORD (OAY) + Y_COORD_OFF
#define JBY_COORD (OAY) + Y_COORD_OFF
#define TEXT_Y 370 /* text y position */
/*
//-------------------------------------
//
// Text justification
//
//-------------------------------------
*/
#define J_LEFT 0 /* left justified text */
#define J_CENTER 1 /* center justified text */
#define J_RIGHT 2 /* right justified text */
/*
//-------------------------------------
//
// keystrokes
//
//-------------------------------------
*/
#define F1 0x3B00
#define F2 0x3C00
#define F3 0x3D00
#define F4 0x3E00
#define F5 0x3F00
#define F6 0x4000
#define F7 0x4100
#define F8 0x4200
#define F9 0x4300
#define F10 0x4400
#define ESC 0x011B
/*
//-------------------------------------
//
// function prototypes
//
//-------------------------------------
*/
void Init (void);
void Uninit (void);
void PutAxis (int x, int y);
void PutButton (int x, int off);
void CrossHair (int x, int y);
void Button (byte status);
void PutCoord (int x, int y, int just, signed value);
void gputs (int x, int y, int color, int just, char *str);
void gerase (int x, int y, int color, int just, char *str);
/*
//-------------------------------------
//
// global variables
//
//-------------------------------------
*/
void *old_image[2]; /* image behind the cross hair */
int Xasp, Yasp; /* X and Y aspect ratios */
int bios_ax0, bios_ay0; /* bios values for joystick A */
int bios_bx0, bios_by0; /* bios values for joystick B */
/*
//-------------------------------------
//
// default colors (vga/ega)
//
//-------------------------------------
*/
int color = YELLOW; /* default color */
int bcolor = RED; /* button color */
int vcolor = YELLOW; /* values color */
int tcolor = GREEN; /* text color */
int hcolor = WHITE; /* cross hair color */
int bkcolor = DARKGRAY; /* background color */
/*
//-------------------------------------
//
// function macros
//
//-------------------------------------
*/
#define X(a) (a)*XREF/Xasp /* X scaling */
#define Y(a) (a)*YREF/Yasp /* Y scaling */
/*
//-------------------------------------
//
// main()
//
//-------------------------------------
*/
void main(void)
{
signed ax, ay, bx, by; /* joystick coordinates */
signed old_ax, old_ay, old_bx, old_by; /* old joystick coordinates */
byte bstat; /* button status */
byte old_bstat = 0; /* old button status */
int key = 0; /* keystroke */
int gport = 1; /* gport mode flag */
union REGS regs; /* CPU registers for bios */
char *mode[] = { "Bios", "Gport" }; /* mode text */
char *cmode[] = { "Real", "Mean" };
byte center = 0;
Init();
old_ax = old_ay = old_bx = old_by =0x7fff;
while(key != ESC)
{
/* If we are not in Gport mode, call the bios to */
/* get the joystick positions. */
if(!gport)
{
regs.h.ah = 0x84;
regs.x.dx = 1;
int86(0x15, ®s, ®s);
ax = ( regs.x.ax - bios_ax0) * BIOS_GAIN;
ay = (-regs.x.bx + bios_ay0) * BIOS_GAIN;
bx = ( regs.x.cx - bios_bx0) * BIOS_GAIN;
by = (-regs.x.dx + bios_by0) * BIOS_GAIN;
ax = limit(ax,1000,-1000);
ay = limit(ay,1000,-1000);
bx = limit(bx,1000,-1000);
by = limit(by,1000,-1000);
}
/* If we are in Gport mode, call GamAxis or GamStick to */
/* get the joystick position for joystick A */
if(gport)
{
#if AXIS
ax = GamAxis(JAX);
ay = GamAxis(JAY);
#else
GamAxes(JA, &ax, &ay);
#endif
}
/* If either coordinate has changed since the last time */
/* it was checked, the screen must be updated with the */
/* new value */
if(ax != old_ax)
{
PutCoord(OAX, JAY_COORD, textwidth(" +0000"), ax);
old_ax = ax;
}
if(ay != old_ay)
{
PutCoord(OAX, JAY_COORD, - textwidth("Y = "), ay);
old_ay = ay;
}
/* Apply the gain divisor to the new coordinates and */
/* update the cross hair. */
ax /= GAIN; ay /= GAIN;
CrossHair(OAX + ax, OAY - ay);
/* If we are in Gport mode, call GamAxis or GamStick to */
/* get the joystick position for joystick B */
if(gport)
{
#if AXIS
bx = GamAxis(JBX);
by = GamAxis(JBY);
#else
GamAxes(JB, &bx, &by);
#endif
}
/* If either coordinate has changed since the last time */
/* it was checked, the screen must be updated with the */
/* new value */
if(bx != old_bx)
{
PutCoord(OBX, JBY_COORD, textwidth(" +0000") , bx);
old_bx = bx;
}
if(by != old_by)
{
PutCoord(OBX, JBY_COORD, - textwidth("Y = "), by);
old_by = by;
}
/* Apply the gain divisor to the new coordinates and */
/* update the cross hair. */
bx /= 7; by /= GAIN;
CrossHair(OBX + bx, OBY - by);
/* If we are in Gport mode, use GamButton. Otherwise */
/* make the call to the bios. */
if(gport)